package com.yld.oa.employee.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.yld.oa.employee.dao.EmployeeDao;
import com.yld.oa.employee.entity.EmployeeEntity;
import com.yld.util.DBUtil;

public class EmployeeDaoImpl implements EmployeeDao {

	@Override
	public void addEmployee(EmployeeEntity employee,Connection connection) {
		
		System.out.println("EmployeeDao connection"+connection);
		
		//2 准备sql 占位符
		String sql ="INSERT INTO OA_EMPLOYEE_T(ID,EMPLOYEE_NAME,DEPARTMENT_ID) VALUES(?,?,?)";
		
		PreparedStatement ps = null;
		
		try {
			//3把字符串封装成可执行的sql命令    准备好的执行语句
			ps = connection.prepareStatement(sql);
			
			//4对参数给定具体的值
			ps.setInt(1, employee.getId());
			ps.setString(2, employee.getEmployeeName());
			ps.setInt(3, employee.getDepartmentId());
			
			//5执行命令
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			DBUtil.closePreparedStatement(ps);
			//DBUtil.closeConnection(connection);
		}

	}

}
